<?php
if ( !isGod() )
	if ( !getRights($mod,'add') )
	{
		showMsg('Không có quyền truy cập vào trang này !','error','center');
		die();
	}
	if ( @$_POST['cmdOK'] != '' )
	{
		$username = (!get_magic_quotes_gpc()) ? addslashes(@$_POST['txtUsername']) : @$_POST['txtUsername'];
		$pwd = (!get_magic_quotes_gpc()) ? addslashes(@$_POST['txtPwd']) : @$_POST['txtPwd'];
		$realname = (!get_magic_quotes_gpc()) ? addslashes(@$_POST['txtRealName']) : @$_POST['txtRealName'];
		$email = (!get_magic_quotes_gpc()) ? addslashes(@$_POST['txtEmail']) : @$_POST['txtEmail'];
		$gid = (!get_magic_quotes_gpc()) ? addslashes(@$_POST['hidGroup']) : intval(@$_POST['hidGroup']);
		$pwd = md5($pwd);
		
		$sql = "SELECT * FROM um_user WHERE username='$username'";
		$rs_c = $link->execute($sql);
		if ( !$rs_c->EOF )	//trung username
		{
			die("Trùng tên đăng nhập !<br /><br /><a href='admin.php?mod=UManager'>Quay về trang trước</a>");
		}
		$rs_c->close();
		
		$sql = "INSERT INTO um_user VALUES('$username','$pwd','$email','$realname',$gid,0)";
		$link->execute($sql);
		
		header("Location: admin.php?mod=UManager");
		die();
	}
	else
	{
		$gid = (!get_magic_quotes_gpc()) ? addslashes(@$_GET['gid']) : intval(@$_GET['gid']);
	}
?>
<script language="javascript">
function ValidateForm()
{
	var obj = docUManagerent.all['frmAddUser'];
	if ( obj.txtUsername.value == "" )
	{
		alert('Chua nhap vao ten dang nhap !');
		obj.txtUsername.focus();
		return false;
	}
	
	if ( obj.txtPwd.value == "" )
	{
		alert('Chua nhap vao mat khau !');
		obj.txtPwd.focus();
		return false;
	}
	
	if ( obj.txtEmail.value != "" )
	{
		if ( ValidateEmail(obj.txtEmail.value) == false )
		{
			alert('Đia chi email khong hop le !');
			obj.txtEmail.focus();
			return false;
		}
		return true;
	}
	else
	{
		alert('Chua nhap vao dia chi Email !');
		obj.txtEmail.focus();
		return false;
	}
	
	return true;
}
</script>
<form action="admin.php?mod=UManager&act=add_user" method="post" name="frmAddUser" onSubmit="return ValidateForm();">
<table width="98%"  border="0" cellspacing="1" cellpadding="0" class="clsMyBorder">
  <tr>
    <td colspan="2" height="23" bgcolor="#336699" class="clsTitle">&nbsp;<img src="images/add_trans.gif" border="0" align="absmiddle"> Thêm mới người dùng</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>  
  <tr>
    <td>&nbsp;Tên đăng nhập</td>
    <td>&nbsp;<input style="background-color: #FFFFCC" name="txtUsername" type="text" size="30" maxlength="15"></td>
  </tr>
  <tr>
    <td>&nbsp;Mật khẩu</td>
    <td>&nbsp;<input style="background-color: #FFFFCC" name="txtPwd" type="password" size="30" maxlength="15"></td>
  </tr>
  <tr>
    <td>&nbsp;Tên thật</td>
    <td>&nbsp;<input name="txtRealName" type="text" size="50" maxlength="50"></td>
  </tr>
  <tr>
    <td>&nbsp;Địa chỉ Email</td>
    <td>&nbsp;<input style="background-color: #FFFFCC" name="txtEmail" type="text" size="50" maxlength="255"></td>
	<input type="hidden" name="hidGroup" value="<?= $gid ?>">
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" style="color: #000066">&nbsp;<i>* Vùng có màu vàng là vùng phải nhập vào nội dung</i></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="right" bgcolor="<?= $clrPanelButton ?>" class="clsPanelButton">
	<input name="cmdOK" type="submit" value="Th&ecirc;m m&#7899;i &raquo;">&nbsp;</td>
  </tr>  
</table>

</form>
